import Vue from 'vue'
import Vuex from 'vuex'
import fa from "element-ui/src/locale/lang/fa";

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    mainShow:true, //导航栏是否显示
    userInfo:localStorage.getItem('userInfo')|| {},//用户名称，用户头像，用户ID
    createListInfo:[],//用户创建的歌单
    collectListInfo:[],//用户收藏的歌单
    dailyRecommandList:[],//用户的每日推荐歌单
    singerClass:[],//根据分类查找出来的歌手列表
    showmenu:false,//默认不显示菜单栏
    showdirection:'ltr',//默认菜单栏在左边显示

    showplayer:false,//显示底部播放器
    pause:true,//播放状态为暂停
    music:{},//存放音乐的名称，歌手，播放进度，链接等
    songSheet:[]//歌单

  },
  mutations: {
    afterlogin(state,payload){
      localStorage.setItem('userInfo',JSON.stringify(payload))//先将传递的数据保存到localstorage中
      state.userInfo = payload
    },
    getCreateListInfo(state,payload){     //获取用户创建的歌单
      state.createListInfo = payload
    },
    getCollectListInfo(state,payload){   //获取用户的收藏的歌单
      state.collectListInfo = payload
    },
    singerClass(state,payload){  //获取歌手列表
      state.singerClass = []
      state.singerClass = payload
    },
    showMenu(state){    //显示更多菜单
      state.showmenu = true
    },
    hideMenu(state){    //隐藏更多菜单
      state.showmenu = false
    },
    getDailyRecommand(state,payload){    //获取用户每日推荐
      state.dailyRecommandList =[]
      state.dailyRecommandList = payload
    },
    showplayer(state){ //显示底部播放器
      state.showplayer = true
    },
    hideplayer(state){  //隐藏底部播放器
      state.showplayer = false
    },
    play(state){ //继续播放音乐
      state.pause = !this.state.pause
    },
    get_music(state,payload){ //拿到用户点击的歌曲的所有信息
      var index = payload.index
      var url = payload.url
      var songItem = payload.songItem
      state.music = {index,url,songItem}
    },
    changePlay(state,payload){
      state.music = payload
    }

  },
  actions: {
    AddMusic(context,payload){
      return new Promise((res,req)=>{
        if(payload.url == null){
          res('歌曲暂无版权');
        }else{
          context.commit("get_music",payload)
          res('歌曲即将播放')
        }
      })
    },
  },
  modules: {
  }
})
